<template>
  <div class="my-counter">
    <!-- 3.4 给-button绑定点击事件，每点击一次，就--  -->
    <button type="button" class="btn btn-light" @click="Clist.goods_count--">
      -
    </button>
    <!-- 3.3输入框 v-model绑定数据-->
    <input type="number" class="form-control inp" v-model="Clist.goods_count" />
    <!-- 3.2给+button绑定点击事件，每点击一次，就++ -->
    <button type="button" class="btn btn-light" @click="Clist.goods_count++">
      +
    </button>
  </div>
</template>

<script>
export default {
  props: ["Clist"],
  // 3.5利用watch监听数据的变化，如果数据<=1时，就把数据=1
  watch: {
    Clist: {
      deep: true,
      handler() {
        if (this.Clist.goods_count <= 1) return (this.Clist.goods_count = 1);
      },
    },
  },
};
</script>

<style lang="less" scoped>
.my-counter {
  display: flex;
  .inp {
    width: 45px;
    text-align: center;
    margin: 0 10px;
  }
  .btn,
  .inp {
    transform: scale(0.9);
  }
}
</style>